﻿Public Class TestieitorGui

    Private _operaciones As IOperaciones
    Private Event MenuClick As EventHandler

    Private Sub testieitorGui_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.myMenuItemCerrar_Click(Nothing, Nothing)
    End Sub

    Private Sub crearMenu()
        Dim mnuFile As New MainMenu()
        Dim myMenuItemAdmin As New MenuItem("&Administrar")
        Dim myMenuItemReportes As New MenuItem("&Reportes")

        Dim myMenuItemUsuario As New MenuItem("&Usuario")
        Dim myMenuItemRol As New MenuItem("&Roles")
        Dim myMenuItemAsignacion As New MenuItem("&Asignacion")
        Dim myMenuItemProyecto As New MenuItem("&Proyecto")

        Dim myMenuItemConfiguracion As New MenuItem("&Configuracion")
        Dim myMenuItemCerrarSesion As New MenuItem("&Cerrar Sesion")

        Dim myMenuItemReporteTestPendientes As New MenuItem("&Reporte Test pendientes")
        Dim myMenuItemReporteTestPorUsuario As New MenuItem("&Reporte Test por Usuario")
        Dim myMenuItemReporteTestDesviacionFechasEstimadas As New MenuItem("&Desviacion de fechas estimadas")

        mnuFile.MenuItems.Add(myMenuItemAdmin)
        mnuFile.MenuItems.Add(myMenuItemReportes)
        myMenuItemAdmin.MenuItems.Add(myMenuItemUsuario)
        myMenuItemAdmin.MenuItems.Add(myMenuItemRol)
        myMenuItemAdmin.MenuItems.Add(myMenuItemAsignacion)
        myMenuItemAdmin.MenuItems.Add(myMenuItemProyecto)
        myMenuItemAdmin.MenuItems.Add(myMenuItemConfiguracion)
        myMenuItemAdmin.MenuItems.Add(myMenuItemCerrarSesion)

        myMenuItemReportes.MenuItems.Add(myMenuItemReporteTestPendientes)
        myMenuItemReportes.MenuItems.Add(myMenuItemReporteTestPorUsuario)
        myMenuItemReportes.MenuItems.Add(myMenuItemReporteTestDesviacionFechasEstimadas)

        AddHandler myMenuItemUsuario.Click, AddressOf Me.myMenuItemUsuario_Click
        AddHandler myMenuItemRol.Click, AddressOf Me.MenuItemRol_Click
        AddHandler myMenuItemAsignacion.Click, AddressOf Me.MenuItemAsignacion_Click
        AddHandler myMenuItemProyecto.Click, AddressOf Me.MenuItemProyecto_Click
        AddHandler myMenuItemCerrarSesion.Click, AddressOf Me.myMenuItemCerrar_Click    

        Me.Menu = mnuFile
    End Sub

    Public Sub habilitar(ByVal value As Boolean)
        Me.panelShortcut.Visible = value
        Me.panelGrid.Visible = value
        Me.panelCentral.Visible = value
        Me.panelBotones.Visible = value

        If value Then
            Me.crearMenu()
        Else
            Me.Menu = Nothing
        End If

    End Sub

    Private Sub myMenuItemCerrar_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Me.habilitar(False)
        Dim sesion As New Sesion(Me)
        Me.panelCentral.Controls.Add(sesion)
        Me.Controls.Add(sesion)
        sesion.Top = (Me.ClientSize.Height - sesion.Height) / 2
        sesion.Left = (Me.ClientSize.Width - sesion.Width) / 2
    End Sub

    Private Sub myMenuItemUsuario_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Me._operaciones = New Usuario
        Me.panelCentral.Controls.Clear()
        Me.panelCentral.Controls.Add(Me._operaciones)
    End Sub

    Private Sub MenuItemRol_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Me._operaciones = New Rol()
        Me.panelCentral.Controls.Clear()
        Me.panelCentral.Controls.Add(Me._operaciones)
    End Sub

    Private Sub MenuItemAsignacion_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Me._operaciones = New Asignacion
        Me.panelCentral.Controls.Clear()
        Me.panelCentral.Controls.Add(Me._operaciones)
    End Sub

    Private Sub MenuItemProyecto_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Me._operaciones = New Proyecto()
        Me.panelCentral.Controls.Clear()
        Me.panelCentral.Controls.Add(Me._operaciones)
    End Sub

    Private Sub btnSuite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSuite.Click
        DialogSuite.ShowDialog()
    End Sub

    Private Sub btnPlan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlan.Click
        Me._operaciones = New Plan()
        Me.panelCentral.Controls.Clear()
        Me.panelCentral.Controls.Add(Me._operaciones)
    End Sub

    Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
        DialogTest.ShowDialog()
    End Sub

    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Me.panelCentral.Controls.Clear()
        _operaciones = Nothing
        Me.dgvGrilla.DataSource = Nothing
    End Sub

    Private Sub btnAgregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAgregar.Click
        If _operaciones IsNot Nothing Then
            Me._operaciones.agregar()
        End If
    End Sub

    Private Sub btnModificar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnModificar.Click
        If _operaciones IsNot Nothing And dgvGrilla.CurrentRow IsNot Nothing Then
            Me._operaciones.modificar()
        End If
    End Sub

    Private Sub btnEliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEliminar.Click
        If _operaciones IsNot Nothing And dgvGrilla.CurrentRow IsNot Nothing Then
            Me._operaciones.eliminar()
        End If
    End Sub

End Class